package cn.mobieteam.add;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Toast;

import com.lidroid.xutils.util.LogUtils;

public abstract class BaseActivity extends Activity implements OnClickListener {
	private static final int ACTIVITY_RESUME = 0;
	private static final int ACTIVITY_STOP = 1;
	private static final int ACTIVITY_PAUSE = 2;
	private static final int ACTIVITY_DESTROY = 3;
	public int activityState;
	// 是否允许全屏
	private boolean mAllowFullScreen = true;

	/**
	 * 控件注入，设置监听及初始化
	 */
	public abstract void init();

	/**
	 * // 点击事件的监听
	 * 
	 * @param v
	 */
	public abstract void widgetClick(View v);

	public void setAllowFullScreen(boolean allowFullScreen) {
		this.mAllowFullScreen = allowFullScreen;
	}

	@Override
	public void onClick(View v) {
		widgetClick(v);
	}

	/***************************************************************************
	 * 
	 * 自定义父类方法
	 * 
	 ***************************************************************************/
	public static Toast toast;

	/**
	 * Toast输出
	 * 
	 * @param text
	 */
	public static void showToast(String text) {
		Toast.makeText(AppContext.get(), text, Toast.LENGTH_LONG).show();
	}

	/**
	 * finsh activity 动画
	 */
	public void finishActivity() {
		finish();
		// 进入动画，出去动画
		overridePendingTransition(R.anim.exit_anim, R.anim.enter_anim);
	}

	/***************************************************************************
	 * 
	 * 打印Activity生命周期
	 * 
	 ***************************************************************************/
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LogUtils.customTagPrefix = "BaseActivity";// 方便调试时过滤 adb logcat 输出
		LogUtils.allowI = true; // adb log 的输出开关
		LogUtils.e("---------onCreate");
		// 竖屏锁定
		// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		// if (mAllowFullScreen) {
		requestWindowFeature(Window.FEATURE_NO_TITLE); // 取消标题
		// }
		AppManager.getAppManager().addActivity(this);
		init();
	}

	@Override
	protected void onStart() {
		super.onStart();
		LogUtils.e("---------onStart");
	}

	@Override
	protected void onResume() {
		super.onResume();
		activityState = ACTIVITY_RESUME;
		LogUtils.e("---------onResume");
	}

	@Override
	protected void onStop() {
		super.onStop();
		activityState = ACTIVITY_STOP;
		LogUtils.e("---------onStop");
	}

	@Override
	protected void onPause() {
		super.onPause();
		activityState = ACTIVITY_PAUSE;
		LogUtils.e("---------onPause");
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		LogUtils.e("---------onRestart");
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		LogUtils.e("---------onBackPressed");
		finishActivity();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		activityState = ACTIVITY_DESTROY;
		LogUtils.e("---------onDestroy");
		AppManager.getAppManager().finishActivity(this);
	}
}
